<template>
	<view class="page" :style="{'min-height':h+'px','padding-top':mt+'px'}">
		<c-nav-bar title="停车场预约"></c-nav-bar>
		<view class="top">
			<view class="t_place">
				<view class="tp_title">{{place}}-停车场</view>
				<view class="tp_addr">
					<image src="https://i.ringzle.com/file/20231106/e3d8756b026849a69a24980df25bf3af.png"></image>
					<text>{{address}}</text>
				</view>
			</view>
			<view class="t_carport">
				<view class="tc_item">
					<text>剩余车位</text>
					<view class="tci_sz">
						<view v-for="(item,index) in nextCarportList" :key="index">{{item}}</view>
					</view>
				</view>
				<view class="tc_item">
					<text>全部车位</text>
					<view class="tci_sz tci_sz_all">
						<view v-for="(item,index) in allCarportList" :key="index">{{item}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="carport_item" v-for="(item,index) in list" :key="index">
			<view class="ci_left">
				<text>{{item.parkadeName}}</text>
				<view class="cil_box">
					<view class="cilb_l">车位</view>
					<view class="cilb_r">剩余<span :class="item.unusedParkingSpace==0?'cr_red':''">{{item.unusedParkingSpace}}</span></view>
				</view>
			</view>
			<view class="ci_right" :class="item.unusedParkingSpace==0?'active':''" @tap="toFill(item)">预约</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				h: uni.getSystemInfoSync().windowHeight,
				mt: uni.getSystemInfoSync().statusBarHeight + 44,
				place:'',
				address:'',
				allCarport:'',
				allCarportList:[],
				nextCarport:'',
				nextCarportList:[],
				list:[]
			}
		},
		onLoad() {
			this.getParkingSpace();
			this.getParkList();
		},
		methods: {
			getParkingSpace(){
				this.$api.get('/travel/wisdom/parkadeReservation/all?type=0').then(res=>{
					if(res.data.code===0){
						this.allCarport = res.data.data.allParkingSpace+'';
						this.nextCarport = res.data.data.allResidueParking+'';
						this.place = res.data.data.nameIsland;
						this.address = res.data.data.locationIsland;
						for (let i=0;i<this.allCarport.length;i++){this.allCarportList.push(this.allCarport.substr(i,1))}
						for (let i=0;i<this.nextCarport.length;i++){this.nextCarportList.push(this.nextCarport.substr(i,1))}
					}else this.$showModal(res.data.msg)
				})
			},
			getParkList(){
				this.$api.get('/travel/wisdom/parkadeReservation/residue?creator=0').then(res=>{
					if(res.data.code===0){
						this.list = res.data.data;
					}else this.$showModal(res.data.msg)
				})
			},
			toFill(item){
				if(item.unusedParkingSpace==0) return
				uni.navigateTo({
					url:'/pagesIndex/parkingService/fillInformation?item='+JSON.stringify({
						place:this.place,
						parkName:item.parkadeName,
						address:this.address,
						latitude:item.latitude,
						longitude:item.longitude
					})
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.page{
		background: #F5F8FA;
		padding: 20rpx 24rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		
		.top{
			width: calc(100% - 48rpx);
			border-radius: 16rpx;
			background: #fff;
			padding: 20rpx 24rpx 40rpx;
			margin-top: 20rpx;
			.t_place{
				.tp_title{
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
				}
				.tp_addr{
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					image{
						width: 20rpx;
						height: 24rpx;
					}
					text{
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #999999;
						margin-left: 6rpx;
					}
				}
			}
			.t_carport{
				margin-top: 20rpx;
				border-top: 1rpx solid rgba(112, 112, 112, .1);
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-top: 25rpx;
				.tc_item{
					width: 50%;
					display: flex;
					flex-direction: column;
					align-items: center;
					&>text{
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #111111;
					}
					.tci_sz{
						display: flex;
						align-items: center;
						&>view{
							margin: 15rpx 5rpx 0;
							width: 48rpx;
							height: 70rpx;
							background: rgba(13, 191, 251, 0.09);
							border-radius: 4rpx;
							line-height: 70rpx;
							text-align: center;
							font-size: 40rpx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #007A69;
						}
						&.tci_sz_all{
							&>view{
								background: #F3F4F6;
								color: #333333;
							}
						}
					}
				}
			}
		}
		
		.carport_item{
			width: calc(100% - 48rpx);
			margin-top: 20rpx;
			padding: 24rpx 24rpx 39rpx;
			background: #fff;
			border-radius: 16rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.ci_left{
				display: flex;
				flex-direction: column;
				&>text{
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #111111;
				}
				.cil_box{
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					&>view{
						height: 40rpx;
						line-height: 40rpx;
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 400;
					}
					.cilb_l{
						width: 70rpx;
						background: #06B86F;
						text-align: center;
						color: #FFFFFF;
						border-top-left-radius: 6rpx;
						border-bottom-left-radius: 6rpx;
					}
					.cilb_r{
						display: flex;
						align-items: center;
						width: 141rpx;
						background: #F3F4F6;
						padding-left: 16rpx;
						color: #111111;
						border-top-right-radius: 6rpx;
						border-bottom-right-radius: 6rpx;
						.cr_red{
							color: #FD2D2D;
						}
					}
				}
			}
			.ci_right{
				width: 122rpx;
				height: 64rpx;
				background: #007A69;
				border-radius: 10rpx;
				line-height: 64rpx;
				text-align: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				&.active{
					background: rgba(170, 170, 170, .42);
				}
			}
		}
	}
</style>